package cn.ld.module.ai.dal.mapper.music;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.ai.controller.admin.music.vo.AiMusicPageInVO;
import cn.ld.module.ai.dal.entity.music.AiMusicEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * AI 音乐 Mapper
 *
 * @author xiaoxin
 */
@Mapper
public interface AiMusicMapper extends BaseMapperX<AiMusicEntity> {

    default List<AiMusicEntity> selectListByStatus(Integer status) {
        return selectList(AiMusicEntity::getStatus, status);
    }

    default PageResult<AiMusicEntity> selectPage(AiMusicPageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<AiMusicEntity>()
                .eqIfPresent(AiMusicEntity::getUserId, inVO.getUserId())
                .eqIfPresent(AiMusicEntity::getTitle, inVO.getTitle())
                .eqIfPresent(AiMusicEntity::getStatus, inVO.getStatus())
                .eqIfPresent(AiMusicEntity::getGenerateMode, inVO.getGenerateMode())
                .betweenIfPresent(AiMusicEntity::getCreateTime, inVO.getCreateTime())
                .eqIfPresent(AiMusicEntity::getPublicStatus, inVO.getPublicStatus())
                .orderByDesc(AiMusicEntity::getId));
    }

    default PageResult<AiMusicEntity> selectPageByMy(AiMusicPageInVO inVO, Long userId) {
        return selectPage(inVO, new LambdaQueryWrapperX<AiMusicEntity>()
                // 情况一：公开
                .eq(Boolean.TRUE.equals(inVO.getPublicStatus()), AiMusicEntity::getPublicStatus, inVO.getPublicStatus())
                // 情况二：私有
                .eq(Boolean.FALSE.equals(inVO.getPublicStatus()), AiMusicEntity::getUserId, userId)
                .orderByAsc(AiMusicEntity::getId));
    }
    
}
